import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const routes = [
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/workbench',
    children: [{
      path: '/workbench',
      name: 'workbench',
      component: () => import('@/views/Workbench/index'),
      meta: { title: '工作台', icon: 'el-icon-eleme' }
    }]
  },
  {
    path: '/park',
    component: Layout,
    name: 'park',
    meta: { title: '园区管理', icon: 'el-icon-office-building' },
    children: [{
      path: '/building',
      name: 'building',
      meta: { title: '楼宇管理' },
      component: () => import('@/views/park/building/index')
    },
    {
      path: '/enterprise',
      name: 'enterprise',
      meta: { title: '企业管理' },
      component: () => import('@/views/park/enterprise/index')
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/car',
    component: Layout,
    name: 'car',
    meta: { title: '行车管理', icon: 'el-icon-bicycle' },
    children: [
      {
        path: '/area',
        name: 'area',
        meta: { title: '区域管理' },
        component: () => import('@/views/Car/area/index.vue')
      },
      {
        path: '/month',
        name: 'month',
        meta: { title: '月卡管理' },
        component: () => import('@/views/Car/month/index.vue')
      },
      {
        path: '/rule',
        name: 'rule',
        meta: { title: '停车缴费管理' },
        component: () => import('@/views/Car/rule/index.vue')
      },
      {
        path: '/stopcar',
        name: 'stopcar',
        meta: { title: '计费规则管理' },
        component: () => import('@/views/Car/stopcar/index.vue')
      }
    ]
  },
  {
    path: '/property',
    component: Layout,
    name: 'property',
    meta: { title: '物业费管理', icon: 'el-icon-wallet' }
  },
  {
    path: '/manage',
    component: Layout,
    name: 'manage',
    meta: { title: '一体杆管理', icon: 'el-icon-wind-power' },
    children: [
      {
        path: '/managex',
        name: 'managex',
        meta: { title: '一体化管理' },
        component: () => import('@/views/Manage/manage/index.vue')
      },
      {
        path: '/warn',
        name: 'warn',
        meta: { title: '告警记录' },
        component: () => import('@/views/Manage/warn/index.vue')
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    name: 'system',
    meta: { title: '系统管理', icon: 'el-icon-chat-round' },
    children: [
      {
        path: '/people',
        name: 'people',
        meta: { title: '员工管理' },
        component: () => import('@/views/System/people/inddex.vue')
      },
      { path: '/cosplay',
        name: 'cosplay',
        meta: { title: '角色管理' },
        component: () => import('@/views/System/cosplay/index.vue')
      }
    ]
  },
  // 新增月卡管理页
  {
    path: '/cardAdd',
    component: () => import('@/views/Car/month/add-card.vue')
  },
  {
    path: '/exterpriseAdd',
    component: () => import('@/views/park/enterprise/commponts/add.vue')
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes: routes
})

const router = createRouter()

// 重置路由方法
export function resetRouter() {
  // 得到一个全新的router实例对象
  const newRouter = createRouter()
  // 使用新的路由记录覆盖掉老的路由记录
  router.matcher = newRouter.matcher
}

export default router
